package com.youyou.fusheng2.View.Adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.youyou.fusheng2.Moudle.OnClick2;
import com.youyou.fusheng2.R;

import java.util.List;
import java.util.Map;

/**
 * @name fusheng2
 * @class name：com.youyou.fusheng2.View.Adapter
 * @anthor 浮生 QQ:2567294605
 * @time 2020/8/27 18:43
 * @to
 */
public class ViewPagerItemAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private List<Map<String, String>> mapList;
    private OnClick2                  onClick2;

    public ViewPagerItemAdapter(OnClick2 onClick2) {
        this.onClick2 = onClick2;
    }

    public void setMapList(List<Map<String, String>> mapList) {
        this.mapList = mapList;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(parent.getContext()).inflate(R.layout.fenlei_imageitem, parent, false);
        return new HomeImage(inflate);
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        Glide.with(holder.itemView.getContext())
                .load(mapList.get(position).get("tpic"))
                .into(((HomeImage) holder).fenlei_image);
        ((HomeImage) holder).fenlei_text.setText(mapList.get(position).get("tname"));
        String tnote = mapList.get(position).get("tnote");
        ((HomeImage) holder).fenlei_note.setText("评分:" + (tnote == null ? 0 : tnote) + "分");
        ((HomeImage) holder).itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                onClick2.listener1(0, mapList.get(position).get("tid"));
            }
        });
    }

    @Override
    public int getItemCount() {
        return mapList.size();
    }

    private class HomeImage extends RecyclerView.ViewHolder {

        private ImageView fenlei_image;
        private TextView  fenlei_text;
        private TextView  fenlei_note;

        public HomeImage(View inflate) {
            super(inflate);
            fenlei_image = inflate.findViewById(R.id.home_image);
            fenlei_text = inflate.findViewById(R.id.home_text);
            fenlei_note = inflate.findViewById(R.id.home_note);
        }
    }
}
